<?php

namespace App\Http\Services;
/*关联用户记录*/

use App\Http\Model\Config;
use App\Http\Model\HdUser;
use App\Http\Model\ShareSendGoods;
use App\Http\Model\User;

class UserServices extends CommonServices
{
    private $user_model;
    private $config_model;
    private $hd_user;


    public function __construct()
    {
        $this->user_model = new User();
        $this->config_model = new Config();
        $this->hd_user = new HdUser();
    }

    /*
     * 查看用户关系
     * */
    public function showUserInvite($user_id)
    {
        return $this->user_model->showUserInvite($user_id);
    }

    /*
     * 添加用户关系
     * @param [$u_id]   新用户id
     * @param [$invite_uid]   邀请用户id
     * */
    public function createUser($u_id, $invite_uid)
    {
        return $this->user_model->createUserInvate($u_id, $invite_uid);
    }

    //查看用户注册时间是否超过活动时间
    public function checkUserRegisterTime($user_id)
    {
        $user = $this->user_model->showUserRegisterTime($user_id);
        if (!$user) return false;
        if (time() - strtotime($user['created_at']) > 30 * 24 * 3600) return false;
        return true;
    }

    /*
         * 我的邀请用户
         * @param [$phone]   注册电话
         * */
    public function myUserInvite($user_id)
    {
        $info = $this->user_model->getMyInviteUser($user_id);
        if (!$info)
            return false;
        foreach ($info as $v) {
            $data[] = $v['user_id'];
        }
        return $data;
    }


    /*
    *  查看邀请新用户信息
    * @param [$user_id]   新用户id
    * */
    public function getInviteUser($invite_user_ids)
    {
        $user_info = $this->user_model->getInviteUsers($invite_user_ids);
        foreach ($user_info as &$v) {
            $v['create_time'] = substr($v['create_time'], 0, 10);
        }
        return $user_info;
    }

    /*
     * 查询邀请用户信息
     * */
    public function inviteUserToNewUser($user_id)
    {
        return $this->user_model->getInviteUserInfo($user_id);

    }


    public function getKkaudioUserInfo($user_id)
    {
        return $this->user_model->getUserInfoByKkaudio($user_id);
    }


    public function getUserDiamond($user_id)
    {
        return $this->user_model->getUserDiamondByKkaudio($user_id);
    }
}